package com.hrbxlh.actionImpl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hrbxlh.dao.*;
import com.hrbxlh.task.DelOverDueMemberListTask;
import com.hrbxlh.task.DelOverDueMemberListener;
import com.hrbxlh.util.*;
import com.hrbxlh.virtualization.service.impl.CourseServiceImpl;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Logger;

/**
 * -------------------------------------------------------
 * Copyright (c) 2017, 鑫联华信息科技股份有限公司
 * All rights reserved.
 * FileName：MemberActionImpl.java
 * Description：人员actionImpl类,负责操作人员数据以及逻辑处理。
 * History：
 * Date           Author               Desc
 * 2017.1.6		  xzx                 建立
 * -------------------------------------------------------
 */

@Component("memberActionImpl")
@Transactional
public class MemberActionImpl {

    @Resource(name = "memberDao")
    private MemberDao memberDao;


    @Resource(name = "homeworkTestDao")
    private HomeworkTestDao homeworkTestDao;

    @Resource(name = "relStuClassDao")
    private RelStuClassDao relStuClassDao;

    @Resource(name = "loginDao")
    private LoginDao loginDao;

    @Resource(name = "depDao")
    private DepDao depDao;

    @Resource(name = "relationDao")
    private RelationDao relationDao;

    @Resource(name = "classDao")
    private ClassDao classDao;

    @Resource(name = "courseActionImpl")
    private CourseActionImpl courseActionImpl;

    @Resource(name = "answerDao")
    private AnswerDao answerDao;

    @Resource(name = "problemDao")
    private ProblemDao problemDao;

    @Resource(name = "sourceDao")
    private SourceDao sourceDao;

    @Resource(name = "roleDao")
    private RoleDao roleDao;

    @Resource(name = "courseServiceImpl")
    private CourseServiceImpl courseServiceImpl;

    @Resource(name = "chapterDao")
    private ChapterDao chapterDao;

    //日志信息
    Logger logger = Logger.getLogger(MemberActionImpl.class.getName());

    /**
     * @param paramMap Map<String,Object> paramMap
     * @return Map<String, String> result true成功，false失败 errorMsg错误信息
     * @throws Exception
     * @description 添加人员的方法，参数key与数据库column对应即可。
     */
    public Map<String, String> addMember(Map<String, Object> paramMap) throws Exception {
        Map<String, String> resultMap = new HashMap<String, String>();
        boolean result = false;
        String failMsg = "";
        try {
            List<Map<String, Object>> memberList = memberDao.getMemberByStuorteaId((String) paramMap.get("stuorteaId"));
            //判断登录名重复
            if (memberList != null && memberList.size() != 0) {
                failMsg = "该用户已存在";
            } else {
                //做特殊字符校验
                if (PubMethods.isSpecialChar(String.valueOf(paramMap.get("stuorteaId"))) || PubMethods.isSpecialChar(String.valueOf(paramMap.get("userSex")))
                        || PubMethods.isSpecialChar(String.valueOf(paramMap.get("telephoneNum"))) || PubMethods.isSpecialChar(String.valueOf(paramMap.get("userName"))) || PubMethods.isSpecialChar(String.valueOf(paramMap.get("password")))
                        || PubMethods.isSpecialChar(String.valueOf(paramMap.get("age")))
                        || PubMethods.isSpecialChar(String.valueOf(paramMap.get("userContect")))) {
                    result = false;
                    resultMap.put("result", String.valueOf(result));
                    resultMap.put("errorMsg", "不可以输入特殊字符,添加人员失败");
                    return resultMap;
                }
                //工号长度校验
                if (String.valueOf(paramMap.get("stuorteaId")).length() > 15 || String.valueOf(paramMap.get("stuorteaId")).length() < 1) {
                    resultMap.put("result", "false");
                    resultMap.put("errorMsg", "学号或工号请输入1-15位数字或英文");
                    return resultMap;
                }
                if (String.valueOf(paramMap.get("userName")).length() > 20) {
                    resultMap.put("result", "false");
                    resultMap.put("errorMsg", "姓名不能超过20个字");
                    return resultMap;
                }
                //手机号校验
                if (!String.valueOf(paramMap.get("telephoneNum")).equals("") && String.valueOf(paramMap.get("telephoneNum")) != null) {
                    boolean telFlag = PhoneValidatorUtil.matchPhoneShowToast(String.valueOf(paramMap.get("telephoneNum")));
                    if (!telFlag) {
                        resultMap.put("result", "false");
                        resultMap.put("errorMsg", "手机号输入不正确");
                        return resultMap;
                    }
                }/*else{
                    resultMap.put("result", "false");
					resultMap.put("errorMsg", "手机号不能为空");
					return resultMap;
				}*/
                //添加人员
                memberDao.addMember(paramMap);
                /*if(Integer.parseInt(String.valueOf(paramMap.get("roleId")))==2){
					//说明添加的是教师
					//添加教师成绩设置
					Map<String,Object>  sourceMap = new HashMap<String,Object>();
					sourceMap.put("stuorteaId", paramMap.get("stuorteaId"));
					sourceMap.put("classPerformance", 0.4);
					sourceMap.put("excellent", 4);
					sourceMap.put("good", 3);
					sourceMap.put("inso", 2);
					sourceMap.put("bad", 1);
					sourceDao.addSorceSet(sourceMap);
				}*/
                result = true;
            }

            if (!result) {
                resultMap.put("errorMsg", failMsg);
            }
            resultMap.put("result", String.valueOf(result));
        } catch (Exception e) {
            throw e;
        }
        return resultMap;
    }

    /**
     * @param paramMap Map<String,Object> paramMap,如果有参数，要与数据库column值相同。
     * @return List<Map<String, Object>> 人员集合
     * @throws Exception
     * @description 查询人员的方法
     */
    public List<Map<String, Object>> getMember(Map<String, Object> paramMap) throws Exception {

        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        try {
            resultList = memberDao.getMember(paramMap);
        } catch (Exception e) {
            throw e;
        }
        return resultList;
    }


    /**
     * @param paramMap Map<String,Object> paramMap
     * @return boolean (true 成功 ,false失败)
     * @throws Exception
     * @description 修改人员的方法，参数key与数据库column一致。
     */
    public boolean saveMember(Map<String, Object> paramMap) throws Exception {
        boolean resultFlag = false;
        String password = "";
        try {

            //做特殊字符校验
            if (PubMethods.isSpecialChar(String.valueOf(paramMap.get("stuorteaId"))) || PubMethods.isSpecialChar(String.valueOf(paramMap.get("userSex")))
                    || PubMethods.isSpecialChar(String.valueOf(paramMap.get("telephoneNum")))) {
                resultFlag = false;
                logger.info("修改人员:存在特殊字符");
                return resultFlag;
            }
            //工号长度校验
            if (String.valueOf(paramMap.get("stuorteaId")).length() > 15 || String.valueOf(paramMap.get("stuorteaId")).length() < 1) {
                resultFlag = false;
                logger.info("修改人员:工号或学号输入1-15数字或英文");
                return resultFlag;
            }
            //手机号校验
            if (!String.valueOf(paramMap.get("telephoneNum")).equals("") && String.valueOf(paramMap.get("telephoneNum")) != null) {
                boolean telFlag = PubMethods.isMobileNum(String.valueOf(paramMap.get("telephoneNum")));
                if (!telFlag) {
                    resultFlag = false;
                    logger.info("修改人员:手机号输入格式不正确");
                    return resultFlag;
                }
            }
            memberDao.saveUser(paramMap);
            resultFlag = true;
        } catch (Exception e) {
            throw e;
        }
        return resultFlag;
    }

    /**
     * @param paramMap Map<String,Object> paramMap
     * @return boolean (true 成功 ,false失败)
     * @throws Exception
     * @description 修改我的信息
     */
    public Map<String, Object> saveMyInfo(Map<String, Object> paramMap) throws Exception {
        boolean resultFlag = false;
        Map<String, Object> returnMap = new HashMap<String, Object>();
        String password = "";
        try {
            if (PubMethods.isSpecialChar(String.valueOf(paramMap.get("stuorteaId"))) || PubMethods.isSpecialChar(String.valueOf(paramMap.get("userSex")))
                    || PubMethods.isSpecialChar(String.valueOf(paramMap.get("userContect")))) {
                resultFlag = false;
                logger.info("修改我的信息:存在特殊字符");
                returnMap.put("resultFlag", resultFlag);
                returnMap.put("msg", "存在特殊字符");
                return returnMap;
            }
            if (!String.valueOf(paramMap.get("telephoneNum")).equals("")) {
                if (!PhoneValidatorUtil.matchPhoneShowToast(String.valueOf(paramMap.get("telephoneNum")))) {
                    resultFlag = false;
                    logger.info("修改我的信息:手机号格式输入不正确");
                    returnMap.put("resultFlag", resultFlag);
                    returnMap.put("msg", "手机号格式输入不正确");
                    return returnMap;
                }
            }
            if (String.valueOf(paramMap.get("userContect")).length() > 200) {
                resultFlag = false;
                logger.info("修改我的信息:简介长度超出限制");
                returnMap.put("resultFlag", resultFlag);
                returnMap.put("msg", "简介长度超出限制");
                return returnMap;
            }
            String textArea = String.valueOf(paramMap.get("userContect")).replaceAll("\n", "<br>");
            textArea = String.valueOf(paramMap.get("userContect")).replaceAll("\r", "<br>");
            paramMap.put("userContect", textArea);
            memberDao.saveMyInfo(paramMap);
            resultFlag = true;
            returnMap.put("resultFlag", resultFlag);
            returnMap.put("msg", "");
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }


    /**
     * @param paramList List<Integer> paramList 人员id集合
     * @return boolean (true 成功 ,false失败)
     * @throws Exception
     * @description 删除教师的方法，传的是每个人员的id。
     */
    public Map<String, Object> delMember(List<String> paramList, HttpServletRequest request, int memType, int marks) throws Exception {

        String resultFlag = "";
        Map<String, Object> returnMap = new HashMap<String, Object>();
        Map<String, Object> paraMap = new HashMap<String, Object>();
        String stuorteaId = "";
        try {
            //获取当前登陆人的id
            Map<String, Object> sessionMap = new SessionValues().getSessionValues(new String[]{"stuorteaId"}, request, "userMsg");
            if (sessionMap == null) {
                returnMap.put("resultMsg", "登录过期请重新登录");
                returnMap.put("resultFlag", false);
                return returnMap;
            }
            stuorteaId = (String) sessionMap.get("stuorteaId");
            //判断当前人是否删除的是自己
            for (int i = 0; i < paramList.size(); i++) {
				/*if(stuorteaId.equals(paramList.get(i))){
					resultFlag = "false";
					returnMap.put("resultFlag", resultFlag);
					returnMap.put("resultMsg", "当前用户正在使用");
					return returnMap;
				}else{*/
                //查询要删除人的角色
                List<Map<String, Object>> mem = memberDao.getMemberByStuorteaId(String.valueOf(paramList.get(i)));
                if (mem.size() == 0) {
                    resultFlag = "true";
                    returnMap.put("resultFlag", resultFlag);
                    returnMap.put("resultMsg", "删除成功");
                    return returnMap;
                }
                paraMap.put("stuorteaId", paramList.get(i));
                if (memType == 1 || (Integer) mem.get(0).get("roleId") == 2 || (Integer) mem.get(0).get("roleId") == 5) {
                    if (marks == 1) {
                        //说明是删除教师,解绑
                        //掉删除教师所有相关的方法
                        returnMap = this.delTeaMethod(paramList, paraMap, marks);
                        if (String.valueOf(returnMap.get("resultFlag")).equals("false")) {
                            //说明出错了不可以继续循环
                            break;
                        }
                    }
                    if (marks == 2) {
                        //说明是删除教师,删除
                        paraMap.put("stuorteaId", paramList.get(i));
                        returnMap = this.delTeaMethod(paramList, paraMap, marks);
                        if (String.valueOf(returnMap.get("resultFlag")).equals("false")) {
                            //说明出错了不可以继续循环
                            break;
                        }
                    }
                } else if (memType == 0 && (Integer) mem.get(0).get("roleId") != 2 && (Integer) mem.get(0).get("roleId") != 5 && (Integer) mem.get(0).get("roleId") != 1) {
                    //说明删除的是管理员
                    //删除人与课程的关联表
                    boolean flag = relStuClassDao.delRelstuCouByStuorteaId(paramList);
                    //删除问题列表
                    problemDao.delProblemByUserId(paramList);
                    //删除回答问题列表
                    answerDao.delAnswerByUserId(paramList);
                    //没有排课信息可以删除人员
                    flag = memberDao.delMember(paramList);
                    if (flag) {
                        returnMap.put("resultMsg", "删除成功");
                        resultFlag = "true";
                    } else {
                        returnMap.put("resultMsg", "删除失败");
                        resultFlag = "false";
                    }
                    returnMap.put("resultFlag", resultFlag);
                } else if (memType == 0 && (Integer) mem.get(0).get("roleId") == 1) {
                    //说明删除的是学生
                    if (marks == 1) {
                        //掉删除学生所有相关的方法
                        returnMap = this.delStuMethod(paramList, marks);
                    }
                    if (marks == 2) {
                        returnMap = this.delStuMethod(paramList, marks);
                    }
                }
//				}
            }
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * @param paramList List<Integer> paramList 人员id集合
     * @return boolean (true 成功 ,false失败)
     * @throws Exception
     * @description 删除教师的方法，传的是每个人员的id。
     */
    public Map<String, Object> isVm(List<String> paramList, int type) throws Exception {
        Map<String, Object> returnMap = new HashMap<String, Object>();
        List<String> stuIdList = new ArrayList<String>();
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        boolean resultFlag = false;
        String msg = "";
        int mark = 0;
        try {
            if (type == 1) {
                //删除班级
                //通过班级id查人员id的集合
                List<Map<String, Object>> idList = memberDao.getUseIdList(paramList);
                for (Map<String, Object> id : idList) {
                    stuIdList.add(String.valueOf(id.get("stuorteaId")));
                }
            }
            if (type == 2) {
                //删除教师
                stuIdList = paramList;
                //判断当前教师是否有排课信息
                for (int i = 0; i < paramList.size(); i++) {
                    Map<String, Object> paraMap = new HashMap<String, Object>();
                    paraMap.put("stuorteaId", paramList.get(i));
                    paraMap.put("isVmMark", 1);
                    resultList = relationDao.getRelStuCourseListById(paraMap);
                    if (resultList != null && resultList.size() != 0) {
                        //说明当前教师又任课信息
                        returnMap.put("msg", paraMap.get("stuorteaId") + "工号的教师存在课程不可删除，删除失败");
                        resultFlag = false;
                        returnMap.put("resultFlag", resultFlag);
                        mark = 1;
                        returnMap.put("mark", mark);
                        return returnMap;
                    }
                }
            }
            if (type == 3) {
                //删除学生
                stuIdList = paramList;
            }
            returnMap.put("mark", mark);
            returnMap.put("resultFlag", resultFlag);
            returnMap.put("msg", msg);
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }


    public Map<String, Object> delTeaMethod(List<String> paramList, Map<String, Object> paraMap, int marks) {
        String resultFlag = "";
        Map<String, Object> returnMap = new HashMap<String, Object>();
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        try {
            //说明是删除教师
            //删除实验相关东西--调用王晨部分
            courseServiceImpl.deleteContainersByStuorteaId(paramList);
            courseServiceImpl.deleteImageOrClusterByStuorteaId(paramList);
            courseServiceImpl.deleteStatisticByStuorteaId(paramList);
            //删除人与课程的关联表
            boolean flag = relStuClassDao.delRelstuCouByStuorteaId(paramList);
            //删除班级与教师的关联表
            flag = relStuClassDao.delRelteaClassByStuOrTeaId(paramList);
            //删除班级与教师的关联表（刑新加的表）
            flag = relStuClassDao.delClassRelByStuOrTeaId(paramList);
            //删除该教师所对应的成绩设置
            sourceDao.delSorceSetById(paraMap);
            //删除问题列表
            problemDao.delProblemByUserId(paramList);
            //删除回答问题列表
            answerDao.delAnswerByUserId(paramList);
            //删除登陆记录
            paraMap.put("list", paramList);
            homeworkTestDao.delLogin(paraMap);
            //查询删除人员未发布or已发布的课程集合
            paraMap.put("releaseMark", 0);
            List<Integer> noRealseCourseList = homeworkTestDao.getNoReaseCourse(paraMap);
            if (noRealseCourseList != null && noRealseCourseList.size() != 0) {
                //删除当前人员未发布的课程
                paraMap.put("courseList", noRealseCourseList);
                homeworkTestDao.delNoReleaseCourse(paraMap);

                //查询未发布or已发布课程与所属的章节的关联
				/*List<Integer> noRealseChapterList = homeworkTestDao.getNoReaseChapter(paraMap);
				if(noRealseChapterList!=null&&noRealseChapterList.size()!=0){
					//删除章节信息
					chapterDao.delChapters(noRealseChapterList);
				}*/
            }
            //查询自己创建的章节
            List<Integer> createList = homeworkTestDao.getCreateChapter(paraMap);
            if (createList != null && createList.size() != 0) {
                //删除自己创建的章节
                chapterDao.delChapters(createList);
            }


            //查询已经发布的课程
			/*paraMap.put("releaseMark",1);
			List<Integer> haveRealseCourseList = homeworkTestDao.getNoReaseCourse(paraMap);
			if(haveRealseCourseList!=null&&haveRealseCourseList.size()!=0){
				paraMap.put("courseList",haveRealseCourseList);
				List<Integer> haveRealseChapterList = homeworkTestDao.getNoReaseChapter(paraMap);
				if(haveRealseChapterList!=null&&haveRealseChapterList.size()!=0){
					paraMap.put("mark",1);
					//删除删除人员自己创建的章节
					chapterDao.delChapters(noRealseChapterList);
				}
			}*/
            //没有排课信息可以删除人员
            flag = memberDao.delMember(paramList);
            if (flag) {
                returnMap.put("resultMsg", "删除成功");
                resultFlag = "true";
            } else {
                returnMap.put("resultMsg", "删除失败");
                resultFlag = "false";
            }
            returnMap.put("resultFlag", resultFlag);
            returnMap.put("resultFlag", resultFlag);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnMap;
    }

    @Transactional
    public Map<String, Object> delStuMethod(List<String> paramList, int marks) {
        String resultFlag = "";
        Map<String, Object> returnMap = new HashMap<String, Object>();
        Map<String, Object> paramMap = new HashMap<String, Object>();
        try {
            //3.0删除学生作业信息
            //查询这些学生的所有作业信息
            List<Map<String, Object>> workList = homeworkTestDao.getWorkByStuIds(paramList);
            DelWorkFileUtil delWorkFileUtil = new DelWorkFileUtil();
            String[] keysArray = {"server_address", "project_name", "tomcatUrl"};
            Map<String, Object> urlmap = ConfigFileUtil.getFileMessage("UtilFile.properties", keysArray);
            String url = (String) urlmap.get("tomcatUrl") + (String) urlmap.get("project_name") + "upload/stuwork/";
            delWorkFileUtil.delWorkFile(workList, "taskAddress", "convertFile", url);
            //删除学生保存的实验报告信息
            Map<String, Object> paMap = new HashMap<String, Object>();
            paMap.put("delType", 2);
            paMap.put("list", paramList);
            homeworkTestDao.delStuTestHistory(paMap);
            //end
            //删除人与课程的关联表
            boolean flag = relStuClassDao.delRelstuCouByStuorteaId(paramList);
            //删除班级学生关联表
            flag = relStuClassDao.delRelStuClassBySId(paramList);
            //删除学生成绩表
            flag = sourceDao.delStuSoruceBystuorteaIdStu(paramList);
            //删除学生提交试卷表
            sourceDao.delStustuquestionBystuorteaIdStu(paramList);
            //删除问题列表
            problemDao.delProblemByUserId(paramList);
            //删除回答问题列表
            answerDao.delAnswerByUserId(paramList);
            //删除学生的作业or实验报告
            paramMap.put("list", paramList);
            paramMap.put("delType", 2);
            homeworkTestDao.delStuTask(paramMap);
            //删除学生的保存的某课程某章节的实验信息（保存的不是提交的）
            homeworkTestDao.delStuTestHistory(paramMap);
            //删除某学生的学习记录
            homeworkTestDao.delStuStudyHistory(paramMap);
            //删除学生的学习笔记
            homeworkTestDao.delStuNote(paramMap);
            //删除学生做的实验相关部分调用王晨接口
//			homeworkTestDao.delVmStatic(paramMap);
            courseServiceImpl.deleteContainersByStuorteaId(paramList);
            courseServiceImpl.deleteStatisticByStuorteaId(paramList);
            //删除学生登陆记录
            homeworkTestDao.delLogin(paramMap);
            //删除人员
            flag = memberDao.delMember(paramList);
            if (flag) {
                returnMap.put("resultMsg", "删除成功");
                resultFlag = "true";
            } else {
                returnMap.put("resultMsg", "删除失败");
                resultFlag = "false";
            }

            returnMap.put("resultFlag", resultFlag);
        } catch (Exception e) {

        }
        return returnMap;
    }

    /**
     * @param paramMap Map<String,Object> paramMap 当前页数：pageNow，每页条数：pageSize，其他条件与column列值要一致。
     * @return Map<String, Object> memberList：人员集合，pageNow：当前页数，totalPage：总页数
     * @throws Exception
     * @description 查询人员列表的方法，分页。
     */
    public Map<String, Object> getMemberList(Map<String, Object> paramMap, HttpServletRequest request) throws Exception {
        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            //获取登录人信息
            SessionValues session = new SessionValues();
            Map<String, Object> sessionValues = session.getSessionValues(new String[]{"stuorteaId"}, request, "userMsg");
            paramMap.put("loginId", sessionValues.get("stuorteaId"));
            int pageNow = 0;
            int pageSize = 10;
            if (paramMap.get("pageNow") != null && paramMap.get("pageSize") != null) {
                pageNow = (Integer) paramMap.get("pageNow");
                pageSize = (Integer) paramMap.get("pageSize");
            }

            if (pageNow != 0) {
                //获取分页数据
//				pageNow = (Integer)paramMap.get("pageNow");
//				pageSize = (Integer)paramMap.get("pageSize");
                int startNum = pageUtil.getSqlStartPos(pageNow, pageSize);
                paramMap.put("startNum", startNum);
            }
            List<Map<String, Object>> memberList = memberDao.getMember(paramMap);
            returnMap.put("memberList", memberList);
            returnMap.put("pageNow", pageNow);

            //获取全部页数
            paramMap.put("pageNow", 0);
            List<Map<String, Object>> allMemberList = memberDao.getMember(paramMap);
            int totalPage = pageUtil.getTotalPage(allMemberList, pageSize);
            returnMap.put("totalPage", totalPage);
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }


    /**
     * @param paramMap Map<String,Object> paramMap 当前页数：pageNow，每页条数：pageSize，其他条件与column列值要一致。
     * @return Map<String, Object> memberList：人员集合，pageNow：当前页数，totalPage：总页数
     * @throws Exception
     * @description 查询过期人员列表的方法，分页。
     */
    public Map<String, Object> getOverMemberList(Map<String, Object> paramMap) throws Exception {
        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            paramMap.put("loginId", "1111");
            int pageNow = 0;
            int pageSize = 10;
            if (paramMap.get("pageNow") != null && paramMap.get("pageSize") != null) {
                pageNow = (Integer) paramMap.get("pageNow");
                pageSize = (Integer) paramMap.get("pageSize");
            }

            if (pageNow != 0) {
                int startNum = pageUtil.getSqlStartPos(pageNow, pageSize);
                paramMap.put("startNum", startNum);
            }
            List<Map<String, Object>> memberList = memberDao.getOverMemberList(paramMap);
            returnMap.put("memberList", memberList);
            returnMap.put("pageNow", pageNow);

            //获取全部页数
            paramMap.put("pageNow", 0);
            List<Map<String, Object>> allMemberList = memberDao.getOverMemberList(paramMap);
            int totalPage = pageUtil.getTotalPage(allMemberList, pageSize);
            returnMap.put("totalPage", totalPage);
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * @param stuorteaId String 学号/工号
     * @return Map<String, Object>
     * @throws Exception
     * @description 通过学号/工号获取用户信息
     */
    public Map<String, Object> getMemberByLogName(String stuorteaId) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            List<Map<String, Object>> memberList = memberDao.getMemberByStuorteaId(stuorteaId);
            if (memberList != null && memberList.size() != 0) {
                returnMap = memberList.get(0);
            }
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * @param paramMap Map<String, Object>
     * @return Map<String, String>
     * @throws Exception
     * @description 登录的方法
     */
    public Map<String, Object> login(Map<String, Object> paramMap, HttpServletRequest request, HttpSession session) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        boolean resultFlag = false;
        String errorMsg = "";
        try {
            //通过学号/工号获取基本信息
            Map<String, Object> memberMessage = this.getMemberByLogName(String.valueOf(paramMap.get("stuorteaId")).trim());
            //3.0 将该人员的角色放到选择参数的位置
            paramMap.put("selecetRoleId", memberMessage.get("roleId"));
            //没加密的密码
            String pwd = String.valueOf(paramMap.get("stuorteaId")).trim() + String.valueOf(paramMap.get("password")).trim();
            String writePassword = DigestUtils.md5Hex(pwd);
            String writeVerficateCode = String.valueOf(paramMap.get("verficateCode")).trim();
            writeVerficateCode = writeVerficateCode.toLowerCase();
            //从session里面取到验证码

            Map<String, Object> sessionMap = PubMethods.getSessionValues(new String[]{"randomString"}, request);
            String verficateCode = (String) sessionMap.get("randomString");
            verficateCode = (verficateCode != null) ? verficateCode.toLowerCase() : verficateCode;
            if (writeVerficateCode == null || writeVerficateCode.equals("")) {
                errorMsg = "请输入验证码";
                returnMap.put("result", false);
                returnMap.put("errorMsg", errorMsg);
                return returnMap;
            }
            if (!writeVerficateCode.equals(verficateCode)) {
                errorMsg = "验证码输入错误";
            } else {
                //判断当前用户是否可以登录
                //获取当前时间
                long nowTime = System.currentTimeMillis();
                //定义日期格式器
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//				DateFormat dateFormat = DateFormat.getDateInstance();
                //从给定字符串的开始解析文本，以生成一个日期，返回的是Date对象
                //从数据库查询系统设置时间
                String time = memberDao.getSetTime();
                Date date = dateFormat.parse(time);
                long setTime = date.getTime();
                if (nowTime - setTime <= 0) {
                    //可以登录
                } else {
                    //所有人员不可以登录
                    errorMsg = "系统崩溃";
                    returnMap.put("result", "false");
                    returnMap.put("errorMsg", errorMsg);
                    return returnMap;
                }
                //做特殊字符校验
                if (PubMethods.isSpecialChar(String.valueOf(paramMap.get("stuorteaId")).trim()) || PubMethods.isSpecialChar(String.valueOf(paramMap.get("verficateCode")).trim())
                        || PubMethods.isSpecialChar(String.valueOf(paramMap.get("password")).trim())) {
                    resultFlag = false;
                    returnMap.put("result", resultFlag);
                    returnMap.put("errorMsg", "不可输入特殊字符，登录失败");
                    return returnMap;
                }
                if (memberMessage == null || memberMessage.get("stuorteaId") == null) {
                    errorMsg = "用户不存在";
                } else {
                    if (!writePassword.equals(String.valueOf(memberMessage.get("password")))) {
                        errorMsg = "密码错误";
                    } else {
                        resultFlag = true;
                        //将当前登陆时间插入Login表
                        loginDao.addLogin(paramMap);
                        //登陆后登陆表的主键
                        long mainId = Long.valueOf( paramMap.get("mainId").toString());
                        int selecetRoleId = Integer.parseInt(String.valueOf(paramMap.get("selecetRoleId")));
                        //唯一标识
                        String onlySid = String.valueOf(memberMessage.get("stuorteaId")) + nowTime;
                        //将用户id，角色id存入session
                        sessionMap.put("userName", memberMessage.get("userName"));
                        sessionMap.put("realRoleId", memberMessage.get("roleId"));
                        sessionMap.put("stuorteaId", memberMessage.get("stuorteaId"));
                        sessionMap.put("roleId", selecetRoleId);
                        sessionMap.put("mainId", mainId);
                        sessionMap.put("onlySid", onlySid);
                        session.setAttribute("userMsg", sessionMap);
                        session.setMaxInactiveInterval(3 * 60 * 60);
                        //将session里面的内容保存在SessonMapUtil类里
                        SessonMapUtil sessonMapUtil = new SessonMapUtil();
                        sessonMapUtil.setSessionMap(sessionMap);
                        //获取登录人的角色名
                        Map<String, Object> roleMap = roleDao.getRoleById(memberMessage);
                        //返回登录人的角色名
                        memberMessage.put("roleName", roleMap.get("roleName"));
                        returnMap.put("memberMessage", memberMessage);
                    }
                }
            }

            if (!resultFlag) {
                returnMap.put("errorMsg", errorMsg);
            }
            returnMap.put("result", String.valueOf(resultFlag));
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * @param paramMap Map<String, Object> 登录名，密码
     * @return Map<String, Object>
     * @throws Exception
     * @description 修改密码
     */
    public Map<String, Object> savePassword(Map<String, Object> paramMap, HttpServletRequest request) throws Exception {

        boolean flag = false;
        String msg = "";
        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            //获取当前登陆人的id
            Map<String, Object> sessionMap = new SessionValues().getSessionValues(new String[]{"stuorteaId"}, request, "userMsg");
            String id = String.valueOf(sessionMap.get("stuorteaId"));
            if (PubMethods.isSpecialChar(String.valueOf(paramMap.get("password"))) || PubMethods.isSpecialChar(String.valueOf(paramMap.get("befPassword")))) {
                flag = false;
                msg = "不可以输入特殊字符";
                returnMap.put("flag", flag);
                returnMap.put("msg", msg);
                return returnMap;
            }
            if (PubMethods.isStrChinese(String.valueOf(paramMap.get("password"))) || PubMethods.isStrChinese(String.valueOf(paramMap.get("befPassword")))) {
                flag = false;
                msg = "不可以输入中文";
                returnMap.put("flag", flag);
                returnMap.put("msg", msg);
                return returnMap;
            }
            if (String.valueOf(paramMap.get("password")).length() > 254 || String.valueOf(paramMap.get("befPassword")).length() > 254) {
                flag = false;
                msg = "密码长度过大";
                returnMap.put("flag", flag);
                returnMap.put("msg", msg);
                return returnMap;
            }
            //通過當前登陸人ｉｄ查詢當前登錄人信息
            List<Map<String, Object>> member = memberDao.getMemberByStuorteaId(id);
            //原密码md5加密
            String befPassword = DigestUtils.md5Hex(id + (String) paramMap.get("befPassword"));
            if (!befPassword.equals(String.valueOf(member.get(0).get("password")))) {
                flag = false;
                msg = "原密码输入不正确";
                returnMap.put("flag", flag);
                returnMap.put("msg", msg);
                return returnMap;
            }
            //新密码md5加密
            String password = DigestUtils.md5Hex(id + (String) paramMap.get("password"));
            if (befPassword.equals(password)) {
                flag = false;
                msg = "原密码与新密码重复，请重新设置";
                returnMap.put("flag", flag);
                returnMap.put("msg", msg);
                return returnMap;
            }
            paramMap.put("password", password);
            paramMap.put("stuorteaId", id);
            memberDao.savePassword(paramMap);
            flag = true;
            msg = "修改成功";
            //将session失效
            request.getSession().invalidate();
            returnMap.put("flag", flag);
            returnMap.put("msg", msg);
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * @param session
     * @return
     * @throws Exception
     * @description 跳转到主页需要的
     */
    public Map<String, Object> skipMain(HttpServletRequest request, HttpSession session) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        Map<String, Object> preParamMap = new HashMap<String, Object>();
        //页面名
        String page = "";
        try {
            String roleId = (String) request.getSession().getAttribute("roleId");
            String stuorteaId = (String) request.getSession().getAttribute("stuorteaId");
            if (roleId.equals("1") || roleId.equals("2")) {
                //通过学号查询当前学生的所学的课程（到时候粘到刑的课程表中）
                preParamMap.put("stuorteaId", stuorteaId);
                List<Map<String, Object>> courseList = memberDao.getCoruseByStuorteaId(preParamMap);
                //通过学号、当前时间查询当前登陆人的课表
                String nowTime = PubMethods.getNowTime(new Date(), 1);
                returnMap.put("courseList", courseList);
            }
            if (roleId.equals("1")) {
                //进入学生主页、需要当前学生的课程、课表
                page = "pc/stuMain";

            }
            if (roleId.equals("2")) {
                //进入教师主页
                page = "pc/teaMain";
            }
            if (roleId.equals("3") || roleId.equals("4")) {
                //是管理员---进入排课主页
                page = "pc/adminMain";
            }
            returnMap.put("page", page);

        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * @param paramMap Map<String, Object> 简介，照片，教师Id
     * @return Map<String, Object>
     * @throws Exception
     * @description 增加教师的简介和照片
     */
    public boolean updatImOrContent(Map<String, Object> paramMap) throws Exception {

        boolean flag = false;
        try {
            memberDao.updatImOrContent(paramMap);
            flag = true;
        } catch (Exception e) {
            throw e;
        }
        return flag;
    }

    /**
     * @param paramMap Map<String, Object> 简介，照片，教师Id
     * @return Map<String, Object>
     * @throws Exception
     * @description 教师/学生信息页修改（包含上传图片和修改简介）
     */
    public boolean updateInfo(Map<String, Object> paramMap) throws Exception {

        boolean flag = false;
        String password = "";
        try {
            String pwd = (String) paramMap.get("password");
            if (!(pwd.equals("")) && pwd != null) {
                //密码加密
                pwd = (String) paramMap.get("stuorteaId") + (String) paramMap.get("password");
                password = DigestUtils.md5Hex(pwd);
            }
            paramMap.put("password", password);
            memberDao.updateInfo(paramMap);
            flag = true;
        } catch (Exception e) {
            throw e;
        }
        return flag;
    }

    /**
     * @param stuorteaId String 学号/工号
     * @return Map<String, Object>
     * @throws Exception
     * @description 通过学号/工号获取用户信息
     */
    public Map<String, Object> getMemberByStuorteaId(String stuorteaId) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            List<Map<String, Object>> memberList = memberDao.getMemberByStuorteaId(stuorteaId);
            if (memberList != null && memberList.size() != 0) {
                returnMap = memberList.get(0);
            } else {
                returnMap = null;
            }
            resultMap.put("memberMap", returnMap);
            resultMap.put("resultFlag", "success");
        } catch (Exception e) {
            resultMap.put("resultFlag", "fail");
            throw e;
        }
        return resultMap;
    }

    /**
     * @param stuorteaId String
     * @return Map<String, Object>
     * @throws Exception
     * @description 通过登录名获取人员信息（管理人员中用到的有部门关联）
     */
    public Map<String, Object> getAdminByStuorteaId(String stuorteaId) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            List<Map<String, Object>> memberList = memberDao.getAdminByStuorteaId(stuorteaId);
            if (memberList != null && memberList.size() != 0) {
                returnMap = memberList.get(0);
            } else {
                returnMap = null;
            }
            resultMap.put("memberMap", returnMap);
            resultMap.put("resultFlag", "success");
        } catch (Exception e) {
            resultMap.put("resultFlag", "fail");
            throw e;
        }
        return resultMap;
    }

    /**
     * xzx
     *
     * @param paramMap String
     * @return Map<String, Object>
     * @throws Exception
     * @description 添加学生
     */
    public Map<String, Object> addStu(Map<String, Object> paramMap) throws Exception {

        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            List<Map<String, Object>> memberList = memberDao.getMemberByStuorteaId((String) paramMap.get("stuorteaId"));
            //判断学号重复
            if (memberList != null && memberList.size() != 0) {
                resultMap.put("result", false);
                resultMap.put("failMsg", "该学号或工号已存在");
                return resultMap;
            } else {
                //特殊字符验证
                if (PubMethods.isSpecialChar((String) paramMap.get("stuorteaId")) || PubMethods.isSpecialChar((String) paramMap.get("userName"))) {
                    resultMap.put("result", false);
                    resultMap.put("failMsg", "不能输入特殊字符");
                    return resultMap;
                }
                //手机号验证
                if (paramMap.get("telephoneNum") != null && !paramMap.get("telephoneNum").toString().equals("")) {
                    boolean telFlag = PhoneValidatorUtil.matchPhoneShowToast(String.valueOf(paramMap.get("telephoneNum")));
                    if (!telFlag) {
                        resultMap.put("result", false);
                        resultMap.put("failMsg", "手机号输入不正确");
                        return resultMap;
                    }
                }
                //生成密码
                //将密码默认给6个0和工号/学号一起用MD5加密
                String pwd = (String) paramMap.get("stuorteaId") + "000000";
                String password = DigestUtils.md5Hex(pwd);
                paramMap.put("roleId", 1);
                paramMap.put("password", password);
                paramMap.put("depId", 0);
                paramMap.put("age", 0);
                paramMap.put("headIcon", "");
                paramMap.put("userContect", "");
                paramMap.put("imageUrl", "");
                paramMap.put("mem_type", 3);
                //获取院系和专业id
                Map<String, Object> classMap = classDao.getClassMsgById(paramMap);
                paramMap.put("professionId", classMap.get("professionId"));
                paramMap.put("departmentId", classMap.get("departmentId"));
                memberDao.addMember(paramMap);
                //添加这个学生与这个班级的关联信息
                relStuClassDao.addRelStuClass(paramMap);
                //查询这个班级对应的课程
                List<Map<String, Object>> courseList = relStuClassDao.getRelCourseByClassId(paramMap);
                if (courseList != null) {
                    if (courseList.size() != 0) {
                        //将该学生与这个班级现拥有的课程进行关联
                        for (int i = 0; i < courseList.size(); i++) {
                            //构造参数
                            courseList.get(i).put("stuorteaId", paramMap.get("stuorteaId"));
                            courseList.get(i).put("selectMark", 1);
                            //保存关联关系的
                            relationDao.saveRelCourseTea(courseList.get(i));
                        }
                    }
                }
                resultMap.put("result", true);
            }
        } catch (Exception e) {
            resultMap.put("result", false);
            e.printStackTrace();
            return resultMap;
        }
        return resultMap;
    }

    /**
     * @param paramMap Map<String, Object>
     * @return Map<String, Object>
     * @throws Exception
     * @description 重置密码
     */
    public Map<String, Object> resetPwd(Map<String, Object> paramMap) throws Exception {

        Map<String, Object> resultMap = new HashMap<String, Object>();
        String errorMsg = "";
        String result = "false";
        try {
            //将密码默认给6个0和工号/学号一起用MD5加密
            String pwd = (String) paramMap.get("stuorteaId") + "000000";
            String password = DigestUtils.md5Hex(pwd);
            paramMap.put("password", password);
            boolean flag = memberDao.resetPwd(paramMap);
            if (flag) {
                errorMsg = "重置成功";
                result = "true";
            } else {
                errorMsg = "重置失败";
            }
            resultMap.put("result", result);
            resultMap.put("errorMsg", errorMsg);

        } catch (Exception e) {
            resultMap.put("result", "fail");
            throw e;
        }
        return resultMap;
    }

    /**
     * @param
     * @return Map<String, Object>
     * @throws Exception
     * @description 查询全部教师
     */
    public List<Map<String, Object>> getTeachers() throws Exception {

        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        try {
            list = memberDao.getTeachers();
        } catch (Exception e) {
            throw e;
        }
        return list;
    }

    /**
     * 班级下的学生
     *
     * @param paramMap Map<String,Object> paramMap 当前页数：pageNow，每页条数：pageSize，其他条件与column列值要一致。
     * @return Map<String, Object> memberList：人员集合，pageNow：当前页数，totalPage：总页数
     * @throws Exception
     * @description 查询人员列表的方法，分页。
     */
    public Map<String, Object> getMemberByClassId(Map<String, Object> paramMap) throws Exception {
        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            int pageNow = 0;
            int pageSize = 10;
            if (paramMap.get("pageNow") != null && paramMap.get("pageSize") != null) {
                pageNow = (Integer) paramMap.get("pageNow");
                pageSize = (Integer) paramMap.get("pageSize");
            }

            if (pageNow != 0) {
                //获取分页数据
                int startNum = pageUtil.getSqlStartPos(pageNow, pageSize);
                paramMap.put("startNum", startNum);
            }
            List<Map<String, Object>> memberList = memberDao.getMemberByClassId(paramMap);
            returnMap.put("memberList", memberList);
            returnMap.put("pageNow", pageNow);

            //获取全部页数
            paramMap.put("pageNow", 0);
            List<Map<String, Object>> allMemberList = memberDao.getMemberByClassId(paramMap);
            int totalPage = pageUtil.getTotalPage(allMemberList, pageSize);
            returnMap.put("totalPage", totalPage);
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * @param paramMap String 学号/工号
     * @return Map<String, Object>
     * @throws Exception
     * @description 用户详情
     */
    public Map<String, Object> getMemberDetailById(Map<String, Object> paramMap) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            List<Map<String, Object>> memberList = memberDao.getMemberDetailById(paramMap);
            returnMap.put("memberList", memberList);
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * @param paramMap Map<String, Object> 头像名称 教师Id
     * @return Map<String, Object>
     * @throws Exception
     * @description 修改头像
     */
    public Map<String, Object> updateHeadIcon(Map<String, Object> paramMap) throws Exception {

        boolean flag = false;
        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            flag = memberDao.updateHeadIcon(paramMap);
            //通过stuorteaId查询当前登陆人信息
            List<Map<String, Object>> mem = memberDao.getMemberByStuorteaId(String.valueOf(paramMap.get("stuorteaId")));
            returnMap.put("flag", flag);
            returnMap.put("headIcon", mem.get(0).get("headIcon"));

        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }

    /**
     * xzx
     *
     * @param jsonStr Id
     * @description 获取某人员的基本信息
     */
    public void getMemberMsg(String jsonStr, HttpServletResponse res) {
        ObjectMapper mapper = new ObjectMapper();
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            map = mapper.readValue(jsonStr, map.getClass());
            //获取这个工号的人的角色信息
            map = memberDao.getMemberMsgById(map);
            //获取这个工号的人的详细信息
            map = memberDao.getMemberMsgById(map);
            map.put("result", "success");
            courseActionImpl.responseStream(res, mapper.writeValueAsString(map));
        } catch (Exception e) {
            map.put("result", "fail");
            e.printStackTrace();
            try {
                courseActionImpl.responseStream(res, mapper.writeValueAsString(map));
            } catch (JsonProcessingException e1) {
                e1.printStackTrace();
            }
        }
    }

    /**
     * xzx
     *
     * @param jsonStr stuorteaId roleId
     * @description 修改人员信息（管理员端）
     */
    public void saveMemberMsg(String jsonStr, HttpServletResponse res) {
        ObjectMapper mapper = new ObjectMapper();
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            map = mapper.readValue(jsonStr, map.getClass());
            map.put("roleId", memberDao.getMemberMsgById(map).get("roleId"));
            //判断特殊字符
            if (courseActionImpl.getMapSpecialMark(res, mapper, map, map)) return;
            //判断手机号格式
            if (map.get("telephoneNum") != null && !map.get("telephoneNum").toString().equals("")) {
                if (!PhoneValidatorUtil.matchPhoneShowToast(String.valueOf(map.get("telephoneNum")))) {
                    map.put("result", "fail");
                    map.put("failMsg", "手机号格式不正确");
                    courseActionImpl.responseStream(res, mapper.writeValueAsString(map));
                    return;
                }
            }

            //20171204sy改
            String textArea = String.valueOf(map.get("userContect")).replaceAll("\n", "<br>");
            textArea = String.valueOf(map.get("userContect")).replaceAll("\r", "<br>");
            if (textArea.length() > 200) {
                map.put("result", "fail");
                map.put("failMsg", "简介超出限制");
                return;
            }
            map.put("userContect", textArea);
			/*end*/
            memberDao.saveMemberMsg(map);
            map.put("result", "success");
            courseActionImpl.responseStream(res, mapper.writeValueAsString(map));
        } catch (Exception e) {
            map.put("result", "fail");
            e.printStackTrace();
            try {
                courseActionImpl.responseStream(res, mapper.writeValueAsString(map));
            } catch (JsonProcessingException e1) {
                e1.printStackTrace();
            }
        }
    }

    /**
     * @param paramMap Map<String, Object> setTime
     * @return Map<String, Object>
     * @throws Exception
     * @description 设置系统可以使用时间
     */
    public void updateSetTime(String setTime) throws Exception {
        try {
            memberDao.updateSetTime(setTime);
        } catch (Exception e) {
            throw e;
        }
    }

    /**
     * @return list
     * @throws Exception
     * @description 黑名单
     */
    public Map<String, Object> blackList(Map<String, Object> paramMap) throws Exception {

        Map<String, Object> returnMap = new HashMap<String, Object>();
        try {
            //获取分页数据
            int pageNow = (Integer) paramMap.get("pageNow");
            int pageSize = (Integer) paramMap.get("pageSize");
            int startNum = pageUtil.getSqlStartPos(pageNow, pageSize);
            paramMap.put("startNum", startNum);
            returnMap.put("pageNow", pageNow);
            List<Map<String, Object>> memberList = memberDao.blackList(paramMap);
            returnMap.put("memberList", memberList);
            paramMap.put("pageNow", 0);
            List<Map<String, Object>> allMemberList = memberDao.blackList(paramMap);
            int totalPage = pageUtil.getTotalPage(allMemberList, pageSize);
            returnMap.put("totalPage", totalPage);
        } catch (Exception e) {
            throw e;
        }
        return returnMap;
    }


    public Map<String, String> addMemberExpiryTime(Map<String, Object> paramMap) throws Exception {
        Map<String, String> resultMap = new HashMap<String, String>();
        boolean result = false;
        String failMsg = "";
        String pwd = "";
        String password = "";
        try {
            List<Map<String, Object>> memberList = memberDao.getMemberByStuorteaId((String) paramMap.get("stuorteaId"));
            //判断登录名重复
            if (memberList != null && memberList.size() != 0) {
                failMsg = "该用户已存在";
            } else {
                //做特殊字符校验
                if (PubMethods.isSpecialChar(String.valueOf(paramMap.get("stuorteaId"))) || PubMethods.isSpecialChar(String.valueOf(paramMap.get("userSex")))
                        || PubMethods.isSpecialChar(String.valueOf(paramMap.get("telephoneNum"))) || PubMethods.isSpecialChar(String.valueOf(paramMap.get("userName")))) {
                    result = false;
                    resultMap.put("result", String.valueOf(result));
                    resultMap.put("errorMsg", "不可以输入特殊字符,添加人员失败");
                    return resultMap;
                }
                //工号长度校验
                if (String.valueOf(paramMap.get("stuorteaId")).length() > 15 || String.valueOf(paramMap.get("stuorteaId")).length() < 1) {
                    resultMap.put("result", "false");
                    resultMap.put("errorMsg", "学号或工号请输入1-15位数字或英文");
                    return resultMap;
                }
                if (String.valueOf(paramMap.get("userName")).length() > 20) {
                    resultMap.put("result", "false");
                    resultMap.put("errorMsg", "姓名不能超过20个字");
                    return resultMap;
                }
                //手机号校验
                if (!String.valueOf(paramMap.get("telephoneNum")).equals("") && String.valueOf(paramMap.get("telephoneNum")) != null) {
                    boolean telFlag = PhoneValidatorUtil.matchPhoneShowToast(String.valueOf(paramMap.get("telephoneNum")));
                    if (!telFlag) {
                        resultMap.put("result", "false");
                        resultMap.put("errorMsg", "手机号输入不正确");
                        return resultMap;
                    }
                }
                if (StringUtils.isBlank(String.valueOf(paramMap.get("password")))) {
                    //将密码和工号/学号一起用MD5加密
                    pwd = String.valueOf(paramMap.get("stuorteaId")) + String.valueOf(paramMap.get("password"));
                    password = DigestUtils.md5Hex(pwd);
                } else {
                    //将密码默认给6个0和工号/学号一起用MD5加密
                    pwd = String.valueOf(paramMap.get("stuorteaId")) + String.valueOf(paramMap.get("password"));
                    password = DigestUtils.md5Hex(pwd);
                }
                paramMap.put("password", password);
                Map<String, Object> timeMap = PubMethods.getExpreTime(Integer.parseInt(String.valueOf(paramMap.get("overdueTime"))));
                paramMap.put("overdueTime", timeMap.get("dateTime"));
                long exptreTime = Long.parseLong(String.valueOf(timeMap.get("time")));
                //添加人员
                memberDao.addMemberExpiryTime(paramMap);
                String stuorteaId = String.valueOf(paramMap.get("stuorteaId"));
                DelOverDueMemberListener.getDelayQueue().put(new DelOverDueMemberListTask(stuorteaId, exptreTime / 1000L));
                result = true;
            }

            if (!result) {
                resultMap.put("errorMsg", failMsg);
            }
            resultMap.put("result", String.valueOf(result));
        } catch (Exception e) {
            throw e;
        }
        return resultMap;
    }

    public boolean deleteMemberExpiryTime() throws Exception {

        try {
            //查询带有过期标识的人员信息
            List<Map<String, Object>> memberList = memberDao.getOverdueMemberList();
            if (memberList == null || memberList.isEmpty()) {
                return false;
            }
            List<String> delList = new ArrayList<>();
            long expreTime = 0;
            long nowTime = 0;
            Object overdueTime = "";
            //将已经过期的人员删除
            for (int i = 0; i < memberList.size(); i++) {
                overdueTime = memberList.get(i).get("overdueTime");
                if (overdueTime == null || StringUtils.isBlank(String.valueOf(overdueTime))) {
                    continue;
                }
                expreTime = PubMethods.getTimeSeconds(String.valueOf(memberList.get(i).get("overdueTime")));
                nowTime = System.currentTimeMillis();
                if (nowTime > expreTime) {
                    delList.add(String.valueOf(memberList.get(i).get("stuorteaId")));
                }
            }

            if (!delList.isEmpty()) {
                memberDao.delMember(delList);
            }

        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return true;
    }
}